package com.mine;

public class DpDemo {
    public static int maxProfit(int[] prices) {
        int maxProfit = 0;
        int minPrice = Integer.MIN_VALUE;

        for (int price : prices) {
            minPrice = price < minPrice ? price : minPrice;
            maxProfit = (price - minPrice) > maxProfit ? (price - minPrice) : maxProfit;
        }
        return maxProfit;
    }

    public static void main(String[] args) {
        System.out.println(maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
    }
}
